package com.weaver.qfengx.map;

import java.util.Map;

public abstract class CustomKeyMap<K, V> extends MapWrapper<K, V> {

    private static final long serialVersionUID = 1L;

    public CustomKeyMap(Map<K, V> raw) {
        super(raw);
    }

    @SuppressWarnings("unchecked")
    @Override
    public V put(K key, V value) {
        return super.put((K) customKey(key), value);
    }

    @Override
    public void putAll(Map<? extends K, ? extends V> m) {
        m.forEach(this::put);
    }

    @Override
    public boolean containsKey(Object key) {
        return super.containsKey(customKey(key));
    }

    @Override
    public V get(Object key) {
        return super.get((K) customKey(key));
    }

    @Override
    public V remove(Object key) {
        return super.remove((K) customKey(key));
    }

    /**
     * 自定义键
     *
     * @param key KEY
     * @return 自定义KEY
     */
    protected abstract Object customKey(Object key);
}
